import { type Directive } from "vue"

/** 禁止重复点击按钮指令 */
export const preventReClick: Directive = {
  mounted(el, binding) {
    el.addEventListener("click", () => {
      if (!el.disabled) {
        el.style.backgroundColor = "#999999"
        el.disabled = true
        setTimeout(() => {
          el.style.backgroundColor = ""
          el.disabled = false
        }, binding.value || 2000)
      }
    })
  }
}
